package com.example.wenhua.mapper;

import com.example.wenhua.entity.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * 用户数据访问层
 */
@Mapper
public interface UserMapper {
    
    /**
     * 查询所有用户
     */
    @Select("SELECT * FROM user")
    List<User> findAll();
    
    /**
     * 根据用户名查询用户
     */
    @Select("SELECT * FROM user WHERE hm = #{hm}")
    User findByHm(String hm);
    
    /**
     * 根据角色查询用户
     */
    @Select("SELECT * FROM user WHERE role = #{role}")
    List<User> findByRole(Integer role);
    
    /**
     * 新增用户
     */
    @Insert("INSERT INTO user(hm, pwd, role) VALUES(#{hm}, #{pwd}, #{role})")
    int insert(User user);
    
    /**
     * 更新用户信息
     */
    @Update("UPDATE user SET pwd=#{pwd}, role=#{role} WHERE hm=#{hm}")
    int update(User user);
    
    /**
     * 更新用户密码
     */
    @Update("UPDATE user SET pwd=#{pwd} WHERE hm=#{hm}")
    int updatePassword(@Param("hm") String hm, @Param("pwd") String pwd);
    
    /**
     * 删除用户
     */
    @Delete("DELETE FROM user WHERE hm = #{hm}")
    int delete(String hm);
    
    /**
     * 验证用户登录
     */
    @Select("SELECT * FROM user WHERE hm = #{hm} AND pwd = #{pwd}")
    User validateLogin(@Param("hm") String hm, @Param("pwd") String pwd);
}